package com.cat.dynamicPlanning02;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/minimum-replacements-to-sort-the-array/description/
 * @create 2025/11/6 17:49
 * @since JDK17
 */

public class Solution50 {
    public long minimumReplacement(int[] nums) {
        long ans = 0;
        int n = nums.length, m = nums[n - 1];
        for (int i = n - 2; i >= 0; i--) {
            int x = (nums[i] - 1) / m;
            ans += x;
            m = nums[i] / (x + 1);
        }

        return ans;
    }
}
